<extend name="Common/common"/>
<block name="main">
    <div class="P_con personInfo">
        <div class="P_main bg_f">
            <form id="myForm">
                <ul class="main_left_right">
                    <li>手机号码<input type="text" name="mobile" id="mobile" class="editInput" placeholder="输入患者手机"/></li>
                    <li>姓名<input type="text" name="name" id='name' class="editInput" placeholder="输入患者姓名"/></li>
                    <li>年龄<input type="text" name="age" id="age" class="editInput" placeholder="输入患者年龄"/></li>
                    <li class="sex">性别<span><em class="current" data-sex="1">男</em><em  data-sex="0">女</em></span></li>
                </ul>
                <input type="hidden" name="sex" value="1" class="mysex">
                <div class="bBth blue"><a href="javascript:void(0)" id="save">完成</a></div>
            </form>
        </div>
    </div>
</block>
<block name="css"></block>
<block name="js">
    <script type="text/javascript" src="__STATIC__/common/js/user.js"></script>
    <script type="text/javascript">
        $(function(){
            //性别切换
            $(".sex em").on('click',function(){
                $(this).addClass('current').siblings().removeClass('current');
                //设置隐藏域的值
                var index = $(this).data('sex');
                $('.mysex').val(index);
            });
            var issend = false;
            //保存事件
            $('#save').click(function(){
                if(issend) return false;
                issend = true;
                //验证手机
                var mobile = $.trim($('#mobile').val());
                if(check_mobile(mobile)==false){
                    layer_msg('请输入正确的手机号');
                    issend = false;
                    return false;
                }
                //验证年龄
                var age = $.trim($('#age').val());
                if(/^\d{1,3}$/.test(age)==false){
                    layer_msg('年龄不合法');
                    issend = false;
                    return false;
                }
                //验证姓名
                var name = $.trim($('#name').val());
                if(name.length>10){
                    layer_msg('姓名超过最大字符');
                    issend = false;
                    return false;
                }
                if(!name){
                    layer_msg('请输入姓名');
                    issend = false;
                    return false;
                }
                var sex = $('.mysex').val();
                $.post(location.href,{mobile:mobile,age:age,name:name,sex:sex},function (data){
                    issend = false;
                    if(data.code==0){
                        if(data.add==1){
                            layer_msg('手机号码已存在,跳转中...',2,function () {
                                location.href=data.url;
                            });
                        }else{
                            location.href=data.url;
                        }
                    }else{
                        layer_msg(data.msg);
                    }
                },'json');
            });
        })
    </script>
</block>